/*
 * Syntelos 'SX'
 * Copyright (C) 1998, 2007  John Pritchard.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */
package syntelos.sx.methods.s;

import syntelos.sx.Response;
import syntelos.sx.Request;

import alto.io.Authentication;
import alto.io.Input;
import alto.io.Output;
import alto.io.Principal;
import alto.lang.Address;
import alto.lang.Component;
import alto.sec.Keys;
import alto.sys.Reference;


/**
 * Authenticate as 'role' for path to '/s/{UID}' (with or without any
 * fext) to list addressof in {UID}.
 * 
 * @see syntelos.io.Authentication#NotApp
 * @see syntelos.sys.Capabilities$RoleRead
 * @since 1.6
 */
public class Addressof
    extends Abstract
{

    public Addressof(){
        super();
    }


    public void respond(Request req)
        throws java.io.IOException,
               java.lang.InterruptedException
    {
        super.respond(req);

        String callerId = IdentifierFor(req);
        if (null != callerId){
            Reference reference = Keys.Tools.ReferenceTo(callerId);
            Address address = reference.getAddress();

            this.println(address.toReference(req));

            this.setContentTypeText();
        }
        else
            this.setStatusBadRequest();
    }
}
